﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ReportManagement;
using System.ComponentModel.Composition;
using GestionSaludOcupacional.Portal.App_Start;

namespace GestionSaludOcupacional.Portal.Controllers
{
    public class ReporteController : PdfViewController
    {
        [Import]
        public Facade Facade;

        public ActionResult Index(int? id)
        {
            if (!id.HasValue)
                return RedirectToAction("Buscar");

            ViewBag.UserId = id;
            return View();
        }

        public ActionResult Buscar()
        {
            return View();
        }

        public JsonResult ListaExamenes(int id)
        {
            var lista = Facade.ObtenerCertificados(id);
            return Json(new { lista }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult MostrarCertificado(int id, string tipo, int individuo)
        {
            if (tipo == "Fisico")
            {
                var entity =
                    Facade.HealthService.ObtenerHistoriaClinicaRegistrosByIndividuo(individuo).FirstOrDefault(x => x.Id == id);

            }
            else if (tipo == "Vision")
            {
                var entity = Facade.HealthService.ObtenerExamenVision(id);
                var vm = Facade.MappingService.GetReportViewModel(entity);
                return View("ExamenVision", vm);
            }
            return View();
        }

        public ActionResult ImprimirCertificado(int id, string tipo, int individuo)
        {
            if (tipo == "Fisico")
            {
                var entity =
                    Facade.HealthService.ObtenerHistoriaClinicaRegistrosByIndividuo(individuo).FirstOrDefault(x => x.Id == id);

            }
            else if (tipo == "Vision")
            {
                var entity = Facade.HealthService.ObtenerExamenVision(id);
                var vm = Facade.MappingService.GetReportViewModel(entity);
                return ViewPdf("Certificado Vision", "ExamenVision", vm);
            }
            return null;
        }
    }
}
